var clickId;
var orderId;
$(function () {
	//选择支付方式
	$(".plList2 span").click(function(){
		$(this).parent().siblings("li").children("span").children("label").removeClass("checked");
		$(this).children("label").addClass("checked");
		$("#btn").val("充值" + $(this).children("input").val() + "元");
		clickId = $(this).attr("id");
	});
	// 支付
	$("#btn").click(function() {
		$(".pop").show();
	})

	var alipay = document.getElementById("alipay");
	alipay.addEventListener("tap", function () {
	    window.location.href = "/Alipay/OrderPayRequest?orderId=" + orderId + "&toUrl='/GoldShopOrder/PaymentSuccess'";
	    //var text = $("#text").html();
	    //var amount = $("#amount").html();
	    //var url = "/Alipay/GetAlipayData";
	    //$.post(url,
        //{
        //    orderId:$("#orderId").val()
        //}, function (data) {
        //    if (data != "") {
        //        $("#formDiv").append(data.alipayData);
        //        $("#alipaysubmit").submit();
        //    }
        //});
	});
	var wxpay = document.getElementById("wxpay");
	wxpay.addEventListener("tap", function () {
	    window.location.href = "/WeChat/OrderPayRequest?orderId=" + orderId + "&toUrl='/GoldShopOrder/PaymentSuccess'&openid=" + $("#openid").val();
	});
});

function createOrder() {
    $.ajax({
        url: "/GoldShopOrder/CreateOrder",
        type: "post",
        data: {
            id: clickId,
            openid: $("#openid").val()
        },
        success: function (data) {
            if (data.code == 1) {
                orderId = data.orderId;
                //location.href = '/GoldShopOrder/PaymentPage?orderId=' + data.orderId + "&openid=@ViewBag.openid";
                //return RedirectToAction("PaymentPage", "GoldShopOrder", new {});
            }
            else {
                alert(data.msg);
            }
        }
    })
}
